// Fill out your copyright notice in the Description page of Project Settings.


#include "AI/Decorator/TUHealthPercentDecorator.h"
#include "AIController.h"
#include "TUUtils.h"
#include "Component/TUHealthComponent.h"

UTUHealthPercentDecorator::UTUHealthPercentDecorator()
{
    NodeName = "Health Percent";
}

bool UTUHealthPercentDecorator::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
    const auto Controller = OwnerComp.GetAIOwner();
    if (!Controller) return false;

    const auto HealthComponent = TUUtils::GetTUPlayerComponent<UTUHealthComponent>(Controller->GetPawn());
    if (!HealthComponent || HealthComponent->IsDead()) return false;

    return HealthComponent->GetHealthPercent() <= HealthPercent;
}

